package cn.gcyl.module.biz.controller.admin.informationtype;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.gcyl.framework.common.pojo.PageParam;
import cn.gcyl.framework.common.pojo.PageResult;
import cn.gcyl.framework.common.pojo.CommonResult;
import cn.gcyl.framework.common.util.object.BeanUtils;
import static cn.gcyl.framework.common.pojo.CommonResult.success;

import cn.gcyl.framework.excel.core.util.ExcelUtils;

import cn.gcyl.framework.apilog.core.annotation.ApiAccessLog;
import static cn.gcyl.framework.apilog.core.enums.OperateTypeEnum.*;

import cn.gcyl.module.biz.controller.admin.informationtype.vo.*;
import cn.gcyl.module.biz.dal.dataobject.informationtype.InformationTypeDO;
import cn.gcyl.module.biz.service.informationtype.InformationTypeService;

@Tag(name = "管理后台 - 信息类型")
@RestController
@RequestMapping("/biz/information-type")
@Validated
public class InformationTypeController {

    @Resource
    private InformationTypeService informationTypeService;

    @PostMapping("/create")
    @Operation(summary = "创建信息类型")
    @PreAuthorize("@ss.hasPermission('biz:information-type:create')")
    public CommonResult<Integer> createInformationType(@Valid @RequestBody InformationTypeSaveReqVO createReqVO) {
        return success(informationTypeService.createInformationType(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新信息类型")
    @PreAuthorize("@ss.hasPermission('biz:information-type:update')")
    public CommonResult<Boolean> updateInformationType(@Valid @RequestBody InformationTypeSaveReqVO updateReqVO) {
        informationTypeService.updateInformationType(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除信息类型")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('biz:information-type:delete')")
    public CommonResult<Boolean> deleteInformationType(@RequestParam("id") Integer id) {
        informationTypeService.deleteInformationType(id);
        return success(true);
    }


    @GetMapping("/get")
    @Operation(summary = "获得信息类型")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('biz:information-type:query')")
    public CommonResult<InformationTypeRespVO> getInformationType(@RequestParam("id") Integer id) {
        InformationTypeDO informationType = informationTypeService.getInformationType(id);
        return success(BeanUtils.toBean(informationType, InformationTypeRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得信息类型分页")
    @PreAuthorize("@ss.hasPermission('biz:information-type:query')")
    public CommonResult<PageResult<InformationTypeRespVO>> getInformationTypePage(@Valid InformationTypePageReqVO pageReqVO) {
        PageResult<InformationTypeDO> pageResult = informationTypeService.getInformationTypePage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, InformationTypeRespVO.class));
    }

}